# 发送群聊
# import requests
# import json

# def get_data():
#     data = {
#         "msg_type": "text",
#         "content": {
#             "text": "你好哦"
#         }
#     }
#     return json.dumps(data,ensure_ascii=True).encode("utf-8")
    
# def req(data):
# 	#webhook
#     url = "https://open.feishu.cn/open-apis/bot/v2/hook/ded835dc-539f-4631-a294-dbdd91f516b6"
#     header = {
#         "Content-type": "application/json",
#         "charset":"utf-8"
#     }
#     requests.post(url,data=data,headers=header)

# if __name__ == '__main__':
#     req(get_data())

# # 发送私聊
import requests
import json

# 获取token
jsonID = {
    "app_id": "cli_a317d7b34df8900e",
    "app_secret": "oNu5Il5WIzllkLLZGeHCfxdelwy0gXRk"
}
headers = {'Content-Type': 'application/json; charset=utf-8'}

token = requests.post('https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal', json=jsonID, headers=headers).json()['tenant_access_token']
params = {"receive_id_type":"open_id"}
data={
    "receive_id":"ou_3f15de9f879499494f08a1cde6db26e0",
    "msg_type": "text",
    "content":"{\"text\":\"我是消息\"}",
    "uuid": "a0d69e20-1dd1-458b-k525-dfeca4015202"
}
print(token)
headers1 = {'Content-Type': 'application/json; charset=utf-8',"Authorization":'Bearer '+ token}
r = requests.post('https://open.feishu.cn/open-apis/im/v1/messages', params=params, headers=headers1,data=json.dumps(data))

print(r.text)

# 送消息给个人：

# from feishu import app 

# app_id = "<your app id>"
# app_secret = "<your app secret>"

# # 初始化飞书应用
# App = app.App(api_token=(app_id, app_secret))

# # 获取token
# token = App.get_access_token()

# # 通过token发送消息
# res = App.send_open_message(token, 
#                         open_id="<user open id>", 
#                         title="消息标题",  
#                         content={
#                             "msg_type": "text",
#                             "content": "消息```Python
# import feishu

# # 初始化 Feishu 开放平台客户端
# client = feishu.Client(
#     app_id="xxx",
#     app_secret="xxx",
# )

# # 发送一条消息给单个用户，用户 ID 为 `user_id`
# client.message.send(
#     chat_id="user_id",
#     message_type="text",
#     content="Hello world!"
# )

# # 发送私聊
import json
import requests

# # 获取token
# jsonID = {
#     "app_id": "cli_a317d7b34df8900e",
#     "app_secret": "oNu5Il5WIzllkLLZGeHCfxdelwy0gXRk"
# }
# headers1 = {'Content-Type': 'application/json; charset=utf-8'}

# token = requests.post('https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal', json=jsonID, headers=headers1).json()['tenant_access_token']

# def send():
#     url = "https://open.feishu.cn/open-apis/im/v1/messages"
#     params = {"receive_id_type":"open_id"}
#     msg = "来啦老弟"
#     msgContent = {
#         "text": msg,
#     }
#     req = {
#         "receive_id": "ou_3f15de9f879499494f08a1cde6db26e0", # chat id
#         "msg_type": "text",
#         "content": json.dumps(msgContent)
#     }
#     payload = json.dumps(req)
#     headers = {
#         'Authorization': 'Bearer '+token, # your access token
#         'Content-Type': 'application/json'
#     }
#     response = requests.request("POST", url, params=params, headers=headers, data=payload)
#     print(response.headers['X-Tt-Logid']) # for debug or oncall
#     print(response.content) # Print Response

# if __name__ == '__main__':
#     send()